﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CommonFunc;

public partial class Manageweb_Default : System.Web.UI.Page
{
    MODEL.Master MM = new MODEL.Master();
    MODEL.Master _MM = new MODEL.Master();

    BLL.Master BM = new BLL.Master();

    protected void Page_Load(object sender, EventArgs e)
    {

    }


    #region 登陆按钮
    protected void IBtn_LoginSubmit_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            if (TB_ValidateCode.Text != Session["Validatacode"].ToString())
            {
                LB_Login.Text = "验证码输入不正确";
            }
            else
            {
                MM.Master_LoginID = TB_LoginName.Text;
                MM.Master_Password = CommonFunction.GetMD5string(TB_LoginPassword.Text);

                DataTable MasterInfo = BM.MasterLogin(MM);
                int MasterID = Convert.ToInt32(MasterInfo.Rows[0]["Master_ID"]);
                if (MasterID > 0)
                {
                    Session["MasterID"] = MasterID.ToString();
                    Session["MasterName"] = TB_LoginName.Text;
                    Session["UserRole"] = MasterInfo.Rows[0]["Master_Role"].ToString();

                    HttpCookie HCK = new HttpCookie("MasterID");

                    HCK.Value = MasterID.ToString();

                    Response.Cookies.Add(HCK);

                    MM.Master_ID = Convert.ToInt32(Session["MasterID"]);
                    MM.Master_LastTime = DateTime.Now;
                    MM.Master_LastIP = Request.ServerVariables["Remote_Addr"].ToString();

                    BM.ModMasterLoginIPAndDateTime(MM);

                    Response.Redirect("Admin.aspx");
                }
                else
                {
                    LB_Login.Text = "此账户不存在或用户名或密码错误";
                }
            }
        }
        catch (Exception ex)
        {
            LB_Login.Text = ex.Message;
        }
    }
    #endregion
}
